package app.kotlin_1.fragment
import android.support.v4.view.PagerAdapter
import android.view.View
import android.view.ViewGroup
import app.kotlin_1.R
import app.kotlin_1.base.BaseFragment
import com.facebook.drawee.view.SimpleDraweeView
import kotlinx.android.synthetic.main.fragment_introduce.view.*

/**
 * Created by 刘智强 on 2017/9/28.
 */
class IntroduceFragment : BaseFragment() {
    private var urlList = mutableListOf<String>()
    private var viewList = mutableListOf<SimpleDraweeView>()


    override fun getLayoutId(): Int = R.layout.fragment_introduce


    override fun initData() {
        urlList.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1506600234158&di=d57a7d4ecc79a3892bc9e124b576ee8b&imgtype=0&src=http%3A%2F%2Fd.hiphotos.baidu.com%2Fbaike%2Fc0%253Dbaike60%252C5%252C5%252C60%252C20%2Fsign%3D652f8b9f28381f308a1485fbc868276d%2F9a504fc2d56285351edd6b8690ef76c6a7ef635c.jpg")
        urlList.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1507194990&di=a639b74a2203dbb5425927160bc65231&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.cxtuku.com%2F00%2F01%2F52%2Fb2315b74cc4b.jpg")
        urlList.add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=496460599,143757670&fm=27&gp=0.jpg")
        urlList.add("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3441084740,4168629766&fm=27&gp=0.jpg")
        urlList.add("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3847007027,2846219577&fm=27&gp=0.jpg")
        urlList.forEach {
            var image = SimpleDraweeView(activity)
            image.setImageURI(it)
            viewList.add(image)
        }
    }

    override fun initView(v: View) {
    }

    override fun initListener() {
        rootView?.vpIntroduce?.adapter = object : PagerAdapter() {
            override fun isViewFromObject(view: View?, `object`: Any?): Boolean {
                return view == `object`
            }

            override fun getCount(): Int = urlList.size
            override fun destroyItem(container: ViewGroup?, position: Int, `object`: Any?) {
                container?.removeView(viewList[position])
            }

            override fun instantiateItem(container: ViewGroup?, position: Int): Any {
                container?.addView(viewList[position])
                return viewList[position]
            }

        }


    }

    override fun setOnClick(v: View?) {
    }

    override fun requestData() {
    }

    override fun setData() {
    }

}